<?php
namespace app\Admin\controller;
use app\Admin\model\Talk as TalkModel;
use app\admin\controller\Base;

class Talk extends Base
{
    public function index()
    {

        $list=db('user_talk')->field('t.*,u.phone,n.title')->alias('t')->join('f_user u','t.uid=u.id')->join('f_note n','t.nid=n.id')->order('t.id')->paginate(5);
        $this->assign('list',$list);
        return view();
    }

    public function edit(){
        $id = input('id');
        $talk = db('user_talk')->find($id);
        if ($talk['status'] == 1) {
            $data = [
                'id' => $id,
                'status' => 0,
            ];
            db('user_talk')->update($data);
            $this->redirect('index');
        } else {
            $data = [
                'id' => $id,
                'status' => 1,
            ];
            db('user_talk')->update($data);
            $this->redirect('index');
        }
    }

    public function del(){
        $id=input('id');
        if(db('user_talk')->delete(input('id'))){
            $this->success('删除评论成功！','index');
        }else{
            $this->error('删除评论失败！');
        }
        
    }
}
